<?php namespace Home\Controller; 
use Hdphp\Controller\Controller;
//内容页控制器
class ListController extends Controller{
	//内容页
	public function index(){
//		标签
//   处理标签名称
      $tid=Q('get.tid',0,'intval');
	  if($tid){
	  	$tagModel=new \Common\Model\Tag;
		$name=$tagModel->where("tid={$tid}")->pluck('tname');
//		统计文章总数
        $arcTagModel=new \Common\Model\ArcTag;		
		$total = $arcTagModel->join('article','article_aid','=','aid')->where("tag_tid=$tid AND is_recycle=0")->count();
//	        根据tid筛选出来的文章
       $arcData=$arcTagModel->join('article','article_aid','=','aid')->join('category','category_cid','=','cid')->where("tag_tid={$tid} AND is_recycle=0")->get();          
		  
	  }  
//	  分类
	     $cid=Q('get.cid',0,'intval');
//		 处理分类名称
         if($cid){
         	 $cateModel = new \Common\Model\Cate;
			 $name = $cateModel->where("cid={$cid}")->pluck('cname');
			//统计该分类（包括子分类）所有的文章总数
			$cids = $cateModel->getSon($cateModel->get(),$cid);
			$cids[] = $cid;			
			$arcModel = new \Common\Model\Arc;			
			$total = $arcModel->where("category_cid in(" . implode(',', $cids) . ") and is_recycle=0")->count();	
	//		分页
	      $page = Page::row(2)->make($total);
		View::with('page',$page);
		
//		SELECT * FROM article JOIN category ON category_cid=cid;
		
		//分配数据
		
//	       $page=Page::url('l' . Q('get.cid') . '_{page}.html')->row(2)->make($total);
	//		p($page);
			
		
//			根据顶级分类，以及下面所有的子分类筛选出的文章
            $arcData = $arcModel->join('category','category_cid','=','cid')->where("category_cid in(" . implode(',', $cids) . ") and is_recycle=0")->get();
            
         }  
		 
		 
		View::with('name',$name);
		View::with('total',$total);
		$arcTagModel=new \Common\Model\ArcTag;
		foreach ($arcData as $k => $v) {
		   $arcData[$k]['tag'] = $arcTagModel->join('tag','tag_tid','=','tid')->where("article_aid={$v['aid']}")->field('tid,tname')->get();
		}
	
//		分配文章数据
      View::with('arcData',$arcData);
		
		
		
		View::make();
	}
	
	
	
	
	

	
	
	
	
	
	
	
	
	
	
	
}
















